using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region ContractInfo

	/// <summary>
	/// ContractInfo object for NHibernate mapped table 'ContractInfo'.
	/// </summary>
	[Serializable]
	public class ContractInfo : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected Nullables.NullableDateTime _dateOfContract;
		protected string _contractNo;
		protected string _producstSold;
		protected string _visitPurposeInContract;
		protected int _quotas;
		protected decimal _unitPrice;
		protected decimal _budget;
		protected Application _application;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public ContractInfo() { }

		public ContractInfo( Nullables.NullableDateTime dateOfContract, string contractNo, string producstSold, string visitPurposeInContract, int quotas, decimal unitPrice, decimal budget, Application application )
		{
			this._dateOfContract = dateOfContract;
			this._contractNo = contractNo;
			this._producstSold = producstSold;
			this._visitPurposeInContract = visitPurposeInContract;
			this._quotas = quotas;
			this._unitPrice = unitPrice;
			this._budget = budget;
			this._application = application;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public Nullables.NullableDateTime DateOfContract
		{
			get { return _dateOfContract; }
			set { _dateOfContract = value; }
		}

		public string ContractNo
		{
			get { return _contractNo; }
			set
			{
				if ( value != null && value.Length > 20)
					throw new ArgumentOutOfRangeException("Invalid value for ContractNo", value, value.ToString());
				_contractNo = value;
			}
		}

		public string ProducstSold
		{
			get { return _producstSold; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for ProducstSold", value, value.ToString());
				_producstSold = value;
			}
		}

		public string VisitPurposeInContract
		{
			get { return _visitPurposeInContract; }
			set
			{
				if ( value != null && value.Length > 200)
					value = value.Substring(0, 200 );
				_visitPurposeInContract = value;
			}
		}

		public int Quotas
		{
			get { return _quotas; }
			set { _quotas = value; }
		}

		public decimal UnitPrice
		{
			get { return _unitPrice; }
			set { _unitPrice = value; }
		}

		public decimal Budget
		{
			get { return _budget; }
			set { _budget = value; }
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is ContractInfo))
				throw new InvalidCastException("This object is not of type ContractInfo");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((ContractInfo)obj).Id);
					break;
				case "DateOfContract":
						relativeValue = ( this.DateOfContract != null ) ? this.DateOfContract.CompareTo(((ContractInfo)obj).DateOfContract) : -1;
					break;
				case "ContractNo":
						relativeValue = ( this.ContractNo != null ) ? this.ContractNo.CompareTo(((ContractInfo)obj).ContractNo) : -1;
					break;
				case "ProducstSold":
						relativeValue = ( this.ProducstSold != null ) ? this.ProducstSold.CompareTo(((ContractInfo)obj).ProducstSold) : -1;
					break;
				case "VisitPurposeInContract":
						relativeValue = ( this.VisitPurposeInContract != null ) ? this.VisitPurposeInContract.CompareTo(((ContractInfo)obj).VisitPurposeInContract) : -1;
					break;
				case "Quotas":
						relativeValue = ( this.Quotas != Convert.ToInt32( null) ) ? this.Quotas.CompareTo(((ContractInfo)obj).Quotas) : -1;
					break;
				case "UnitPrice":
						relativeValue = ( this.UnitPrice != Convert.ToDecimal( null) ) ? this.UnitPrice.CompareTo(((ContractInfo)obj).UnitPrice) : -1;
					break;
				case "Budget":
						relativeValue = ( this.Budget != Convert.ToDecimal( null) ) ? this.Budget.CompareTo(((ContractInfo)obj).Budget) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (ContractInfo.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
